// matrix_operations.h
#ifndef MATRIX_OPERATIONS_H
#define MATRIX_OPERATIONS_H

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

// 矩阵结构定义
typedef struct {
    uint32_t rows;     // 矩阵行数
    uint32_t cols;     // 矩阵列数
    uint8_t* data;  // 矩阵数据（一维数组存储）
} Matrix;

typedef struct{
    int size;
    uint8_t* data;
}Vector;

// 内存管理函数
Matrix create_matrix(uint32_t rows, uint32_t cols);
void free_matrix(Matrix mat);
Matrix copy_matrix(Matrix mat);

// 矩阵基本运算
void matrix_add(Matrix a, Matrix b, Matrix result);
void matrix_mul(Matrix a, Matrix b, Matrix result);
void mul_matrix(int rowsB, int colsC, int rowsC, Matrix B, Matrix C, Matrix *D);
void add_matrix(int rows, int cols, double mat1[rows][cols], double mat2[rows][cols], double result[rows][cols]);


// 调试工具
void print_matrix(Matrix mat, int limit);
Matrix read_txt_data(const char* filename);
void matrix_to_vector(int rows, int cols, double matrix[rows][cols], double vector[1][rows * cols]);
void vector_to_matrix(int rows, int cols, double vector[1][rows * cols], double matrix[rows][cols]);
Matrix read_matrix(const char *filename);
Matrix create_empty_matrix();

void softmax(int rows, int cols, double input[rows][cols], double output[rows][cols]);

#endif
